<script language="JavaScript" type="text/javascript">
<? sajax_show_javascript(); ?>

// ***** CONFERENCES *************************************************

function addConference() {
	var content = '<div id="addEditConference2">';
	content    += '<h3>Add Conference</h3><table style="border: none;" class="inputForm"><tr>';
	content    += '<td style="width: 40%; vertical-align: top;">Conference Date(s)</td>';
	content    += '<td style="width: 60%;">';
	content    += '<input type="text" name="dateStart" id="dateStart" style="width: 80px;" onclick="this.blur(); return showCalendar(\'dateStart\', \'y-mm-dd\');" value="">';
	content    += '&nbsp;<b>To</b>&nbsp;';
	content    += '<input type="text" name="dateEnd" id="dateEnd" style="width: 80px;" onclick="this.blur(); return showCalendar(\'dateEnd\', \'y-mm-dd\');" value="">';
	content    += '</td></tr><tr><td style="vertical-align: top;">';
	content    += 'Conference Title</td><td>';
	content    += '<input type="text" id="title" style="width: 300px;">';
	content    += '</td></tr><tr><td style="vertical-align: top;">';
	content    += 'Conference Description</td><td>';
	content    += '<textarea id="description" style="width: 300px; height: 80px;"></textarea>';
	content    += '</td></tr><tr><td style="vertical-align: top;">';
	content    += 'Conference Website</td><td>';
	content    += '<input type="text" id="url" style="width: 300px;" value="http://" onFocus="this.value=\'\'">';
	content    += '</td></tr><tr><td style="vertical-align: top;"></td><td><input type="submit" onClick="addConferenceConfirm(); return false;" value="Add Conference">';
	content    += '<input type="button" value="Close" onClick="closeWindow(\'addEditConference\'); return false;">';	
	content    += '</td></tr></table></div>';			    
	
	document.getElementById('addEditConference').style.display = '';			 
	document.getElementById('addEditConference').innerHTML = content;
}

function editConference(cID) {
	x_editConference(cID,returnEditConferenceDisplay);
}

function returnEditConferenceDisplay(string) {
	document.getElementById('addEditConference').style.display = '';			 
	document.getElementById('addEditConference').innerHTML = string;
}

function editConferenceConfirm(cID) {
	// Get variables
	var dateStart   = document.getElementById('dateStart').value;
	var dateEnd     = document.getElementById('dateEnd').value;
	var title       = removeChar(document.getElementById('title').value);
	var description = removeChar(document.getElementById('description').value);
	var url         = removeChar(document.getElementById('url').value);
	
	// Error check
	if (title == '') {
		var error = 1;
		document.getElementById('warning').innerHTML = '<div class="errorMessage">You must enter a title.</div>';
	}
	if (dateStart == '') {
		var error = 1;
		document.getElementById('warning').innerHTML = '<div class="errorMessage">You must enter a date.</div>';
	}
	if (error != 1) {
		x_editConferenceConfirm(dateStart,dateEnd,title,description,url,cID,returnRedrawItems);
	}	
}

function addConferenceConfirm() {
	// Get variables
	var dateStart   = document.getElementById('dateStart').value;
	var dateEnd     = document.getElementById('dateEnd').value;
	var title       = removeChar(document.getElementById('title').value);
	var description = removeChar(document.getElementById('description').value);
	var url         = removeChar(document.getElementById('url').value);
	
	// Error check
	if (title == '') {
		var error = 1;
		document.getElementById('warning').innerHTML = '<div class="errorMessage">You must enter a title.</div>';
	}
	if (dateStart == '') {
		var error = 1;
		document.getElementById('warning').innerHTML = '<div class="errorMessage">You must enter a date.</div>';
	}
	if (error != 1) {
		x_addConference(dateStart,dateEnd,title,description,url,returnRedrawItems);
	}	
}

// ***** NEWSLETTERS *************************************************

function addNewsletter() {
	var content = '<div id="addEditNewsletter2">';
	content    += '<h3>Add Newsletter</h3><table style="border: none;" class="inputForm"><tr>';
	content    += '<td style="width: 40%; vertical-align: top;">Newsletter Title</td>';
	content    += '<td style="width: 60%;">';
	content    += '<input type="text" id="title" style="width: 300px;">';
	content    += '</td></tr><tr><td style="vertical-align: top;">';
	content    += 'Newsletter Description</td><td>';
	content    += '<textarea id="description" style="width: 300px; height: 80px;"></textarea>';
	content    += '</td></tr><tr><td style="vertical-align: top;">';
	content    += 'Newsletter Website</td><td>';
	content    += '<input type="text" id="url" style="width: 300px;" value="http://" onFocus="this.value=\'\'">';
	content    += '</td></tr><tr><td style="vertical-align: top;"></td><td><input type="submit" onClick="addNewsletterConfirm(); return false;" value="Add Newsletter">';
	content    += '<input type="button" value="Close" onClick="closeWindow(\'addEditNewsletter\'); return false;">';	
	content    += '</td></tr></table></div>';			    
	
	document.getElementById('addEditNewsletter').style.display = '';			 
	document.getElementById('addEditNewsletter').innerHTML = content;
}
function addNewsletterConfirm() {
	// Get variables
	var title       = removeChar(document.getElementById('title').value);
	var description = removeChar(document.getElementById('description').value);
	var url         = removeChar(document.getElementById('url').value);
	
	// Error check
	if (title == '') {
		var error = 1;
		document.getElementById('warning').innerHTML = '<div class="errorMessage">You must enter a title.</div>';
	}
	if (error != 1) {
		x_addNewsletter(title,description,url,returnRedrawItems);
	}	
}

function editNewsletter(nID) {
	x_editNewsletter(nID,returnEditNewsletterDisplay);
}

function returnEditNewsletterDisplay(string) {
	document.getElementById('addEditNewsletter').style.display = '';			 
	document.getElementById('addEditNewsletter').innerHTML = string;
}

function editNewsletterConfirm(nID) {
	// Get variables
	var title       = removeChar(document.getElementById('title').value);
	var description = removeChar(document.getElementById('description').value);
	var url         = removeChar(document.getElementById('url').value);
	
	// Error check
	if (title == '') {
		var error = 1;
		document.getElementById('warning').innerHTML = '<div class="errorMessage">You must enter a title.</div>';
	}
	if (error != 1) {
		x_editNewsletterConfirm(title,description,url,nID,returnRedrawItems);
	}	
}

// ***** SERVICE PROVIDERS *************************************************

// ***** COMMON FUNCTIONS *************************************************

function confirmDeleteItem(itemID,itemType) {
	if (itemType == 'conference') { itemDivID = 'Conference'; }
	else if (itemType == 'newsletter') { itemDivID = 'Newsletter'; }
	var OK = confirm("Are you sure you want to delete this "+itemType+"?");
	if (OK == true) {
		x_deleteItem(itemID,itemType,returnRedrawItems);
		ajaxAnim('ajaxAnim'+itemDivID);
	}
}

function returnRedrawItems(string) {
	var stringArray = string.split('|');
	var itemList    = stringArray[0];
	var itemType      = stringArray[1];
	
	if (itemType == 'conference') { itemDivID = 'Conference'; }
	else if (itemType == 'newsletter') { itemDivID = 'Newsletter'; }
	
	document.getElementById(itemType).innerHTML = itemList;
	document.getElementById('addEdit'+itemDivID).style.display = 'none';			 
	document.getElementById('addEdit'+itemDivID).innerHTML = '';
	ajaxAnimStop('ajaxAnim'+itemDivID);
}

function toggleActive(itemID,activeState,itemType) {
	x_toggleActive(itemID,activeState,itemType,returnToggleActive);
}

function returnToggleActive(string) {
	var stringArray = string.split('|');
	var newState    = stringArray[0];
	var itemID      = stringArray[1];
	var itemType    = stringArray[2];
	var tdID = itemType+'ToggleActive_'+itemID;
	
	//alert(tdID);
	
	if (newState == 1) {
		var content = '<a href="#" onClick="toggleActive('+itemID+','+newState+',\''+itemType+'\'); return false;" title="Show on site"><img src="images/iconYes.gif" style="border: none;" alt="Show on site"></a>';
	} else if (newState == 0) {
		var content = '<a href="#" onClick="toggleActive('+itemID+','+newState+',\''+itemType+'\'); return false;" title="Remove from site"><img src="images/iconNo.gif" style="border: none;" alt="Remove from site"></a>';
	}
	document.getElementById(tdID).innerHTML = content;
}
</script>